/**
 * 欢迎页面对应的JS
 * 
 * @author li.sanlai@ustcinfo.com
 */


Home = function() {
	//var areaCode = ['A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S'];
	//var areaName = ["合肥","芜湖","蚌埠","淮南","马鞍山","淮北","铜陵","安庆","黄山","阜阳","宿州","滁州","六安","宣城","巢湖","贵池","亳州"];
	return {
		
		init:function(){
			Home.initPortal();
			Home.initStyle();
			Home.initServReggrid();
			Home.initservModifygrid();
			Home.initservModifydatagrid();
			Home.initmemberShipIctGrid();
		},
		
		//初始化portal
		initPortal : function(){
			
			$.pp.portal({
				border:false,
				fit:true
			});
			
		},
		
		//初始化样式
		initStyle : function(){
			var height = eval($.pp.height());
			var width = eval($.pp.width()-50);
//			var halfHeight = eval(height/2);
//			$.qydd.width(width);
//			$.qydd.height(height);
//			$.qyddTab.width(width);
//			$.qyddTab.height(height);
		},
		
		//服务开通
		servReg:function(id,prdCode,ecName,ecCode,priority,adminUser,adminUfid){
			$('body').mask('正在开通……');
			$.ajax({
				  url: "/interface/registServ.htm",
				  type:'post',
				  timeout:300000,
				  data:{
				  	'prdCode':prdCode,
				  	'ecName':ecName,
				  	'ecCode':ecCode,
				  	'priority':priority,
				  	'adminUser':adminUser,
				  	'adminUfid':adminUfid
				  },
				  context: document.body,
				  success: function(data){
				  	$('body').unmask();
				  	if(data.success==true){
				  		Ict.slideMsg('<font style="color:green;">' + ecName + "&nbsp;&nbsp;已经开通服务 </font>",1500);
				  		//设置订单状态
			  			$.ajax({
							  url: "/interface/updateServOrder.htm",
							  type:'post',
							  data:{
							  	'id':id,
							  	'ecName':ecName
							  },
							  context: document.body,
							  success:function(data){
					  	  		$('#servReggrid').datagrid('reload');
							  }
			  			});
				  		
				  	}else{
				  		Ict.error(data.msg);
				  	}
				  	  	
				  },
				  error:function(){
				  		$('body').unmask();
				  		Ict.info('服务开通失败');
				  }
			});
		},
		
		/**
		 * 处理成员订购订单
		 */
		handleMemberShipOrder:function(id){
			$('body').mask('正在处理订单……');
			$.ajax({
				  url: "/interface/handleMemberShipOrder.htm",
				  type:'post',
				  data:{
				  	'id':id
				  },
				  context: document.body,
				  success: function(data){
				  	$('body').unmask();
				  	if(data.success==true){
				  		Ict.slideMsg('<font style="color:green;">'+data.msg+'</font>',1500);
				  		//设置订单状态
			  			$.ajax({
							  url: "/interface/updateMemberShipOrder.htm",
							  type:'post',
							  data:{
							  	'id':id
							  },
							  context: document.body,
							  success:function(data){
					  	  		$('#memberShipIctGrid').datagrid('reload');
							  }
			  			});
				  		
				  	}else{
				  		Ict.error(data.msg);
				  	}
				  	  	
				  },
				  error:function(){
				  		$('body').unmask();
				  		Ict.info('成员订购订单处理失败');
				  }
			});
		},
		
		//成员订购订单列表初始化
		initmemberShipIctGrid:function(){
			$('#memberShipIctGrid').datagrid({
				url:'/interface/memberShipIctList.htm',
				fit:true,
				striped:true,
				nowrap:true,
				loadMsg:'加载中 ……',
				animate:true,
				checkbox:true,
				pagination:true,
				rownumbers:true,
				fitColumns:true,
				border:true,
				columns:[[
					{field:'id',title:'',width:50,checkbox : true},
					{field:'ecCode',title:'EC企业代码',width:70},
				    {field:'ecName',title:'EC企业名称',width:200},
				    {field:'prdOrdNum',title:'集团产品代码',width:70,formatter:function(value,rowData,index){
				    	if(value == 'J0185'){
				    		return '销售管家';
				    	}else if(value = 'J0186'){
				    		return '外勤管家';
				    	}else{
				    		return '未知产品';
				    	}
				    }},
				    {field:'interUpdateTime',title:'订单时间',width:80},
				    {field:'requestMessage',title:'请求报文',width:40,formatter:function(value,rowData,index){
				    	if(value != null){
				    		return '<a href="javascript:Home.showRequestMessager(\''+rowData.id+'\')" >查看</a>';
				    	}
				    }},
				    {field:'state',title:'状态',width:40,formatter: function(value,row,index){
						if (value=='1'){
							return '<font style="color:green;">已处理</font>';
						} else {
							return '<font style="color:red;">未处理</font>';
						}
					}},
					{field:'optType',title:'操作',width:50,formatter: function(value,row,index){
						return '<a href="javascript:Home.handleMemberShipOrder(\''+ row.id +'\');" >处理订单</a>';
					}}
				]]
			});
		},
		
		//查看请求报文
		showRequestMessager:function(id){
			$.post("/interface/memberShipIctList.htm",{page:1,rows:10,id:id},function(data){
				var d = data.rows;
				$('#requestMsg').html(d[0].requestMessage);
				art.dialog({
					lock: true,
					title:'请求报文信息',
					padding: 0,
				    content: document.getElementById('requestMsgDIV'),
				    cancelVal: '关闭',
				    cancel:true
				});
			});
		},
		
		//提交服务变更请求
		changeServiceState:function(id,optType,ecCode,ecName,prdCode){
			var opt = optType=='2'?'退订':optType=='3'?'暂停':optType=='4'?'恢复':'-1';
			$('body').mask('正在'+opt+'……');
			$.ajax({
				  url: "/interface/changeServiceState.htm",
				  type:'post',
				  data:{
				  	'optType':optType,
				  	'ecCode':ecCode,
				  	'prdCode':prdCode
				  },
				  context: document.body,
				  success: function(data){
				  	$('body').unmask();
				  	if(data.success==true){
				  		Ict.slideMsg('<font style="color:green;">' + ecName + "&nbsp;&nbsp;"+opt+"成功 </font>",1500);
				  		//设置订单状态
			  			$.ajax({
							  url: "/interface/updateServerStateOrder.htm",
							  type:'post',
							  data:{
							  	'id':id
							  },
							  context: document.body,
							  success:function(data){
					  	  		$('#servModifydatagrid').datagrid('reload');
							  }
			  			});
				  		
				  	}else{
				  		Ict.error(data.msg);
				  	}
				  	  	
				  },
				  error:function(){
				  		$('body').unmask();
				  		Ict.info('服务'+opt+'失败');
				  }
			});
		},
		//初始化服务变更列表
		initservModifydatagrid:function(){
			$('#servModifydatagrid').datagrid({
				url:'/interface/servModifyList.htm',
				fit:true,
				striped:true,
				nowrap:true,
				loadMsg:'加载中 ……',
				animate:true,
				checkbox:true,
				pagination:true,
				rownumbers:true,
				fitColumns:true,
				border:true,
				columns:[[
					{field:'id',title:'',width:50,checkbox : true},
					{field:'ecName',title:'企业名称',width:200},
				    {field:'ecCode',title:'企业编码',width:100},
				    {field:'prdCode',title:'产品类型',width:70,formatter:function(value,rowData,index){
				    	if(value == 'J0185'){
				    		return '销售管家';
				    	}else if(value = 'J0186'){
				    		return '外勤管家';
				    	}else{
				    		return '未知产品';
				    	}
				    }},
				    {field:'serviceCode',title:'业务编码',width:100},
				    {field:'serviceName',title:'业务名称',width:100},
				    {field:'optTime',title:'受理时间',width:100},
				    {field:'execTime',title:'生效时间',width:100},
				    {field:'interUpdateTime',title:'订单时间',width:80},
				    {field:'state',title:'状态',width:50,formatter: function(value,row,index){
						if (value=='1'){
							return '<font style="color:green;">已处理</font>';
						} else {
							return '<font style="color:red;">未处理</font>';
						}
					}},
					{field:'optType',title:'操作',width:70,formatter: function(value,row,index){
						if(value == '2'){
							return row.state=='1'?'<font style="color:green;">已退订</font>':'<a href="javascript:Home.changeServiceState(\''+row.id+'\',\'2\',\''+row.ecCode+'\',\''+row.ecName+'\',\''+row.prdCode+'\')" >关闭</a>';
						}else if(value == '3'){
							return row.state=='1'?'<font style="color:green;">已暂停</font>':'<a href="javascript:Home.changeServiceState(\''+row.id+'\',\'3\',\''+row.ecCode+'\',\''+row.ecName+'\',\''+row.prdCode+'\')" >暂停</a>';
						}else if(value == '4'){
							return row.state=='1'?'<font style="color:green;">已恢复</font>':'<a href="javascript:Home.changeServiceState(\''+row.id+'\',\'4\',\''+row.ecCode+'\',\''+row.ecName+'\',\''+row.prdCode+'\')" >恢复</a>';
						}else{
							return '--';
						}
					}}
				]]
			});
		},
		
		//初始化服务修改订单表格
		initservModifygrid:function(){
			$('#servModifygrid').datagrid({
				url:'/interface/servOrderList.htm?optType=1',
				fit:true,
				idField:'id',
				striped:true,
				nowrap:true,
				loadMsg:'加载中 ……',
				animate:true,
				checkbox:true,
				pagination:true,
				rownumbers:true,
				fitColumns:true,
				border:true,
				columns:[[
					{field:'id',title:'',width:50,checkbox : true},
					{field:'area',title:'地市',width:40},
					{field:'ec_name',title:'企业名称',width:200},
				    {field:'ec_code',title:'企业编码',width:100},
				    {field:'prd_code',title:'产品类型',width:70,formatter:function(value,rowData,index){
				    	if(value == 'J0185'){
				    		return '销售管家';
				    	}else if(value = 'J0186'){
				    		return '外勤管家';
				    	}else{
				    		return '未知产品';
				    	}
				    }},
				    {field:'priority',title:'管理员手机',width:80},
				    {field:'admin_user',title:'管理员用户名',width:80,formatter: function(value,row,index){
				    	return value + '@' + row.ec_code;
					}},
				    {field:'access_no',title:'登录地址',width:200,formatter: function(value,row,index){
				    	if(value && value!=''){
					    	var url = basePath + 'login/' + value;
							return url;
				    	}else{
				    		return '';
				    	}
					}},
				    {field:'admin_ufid',title:'管理员密码',width:60},
				    {field:'inter_update_time',title:'订单时间',width:80},
				    {field:'state',title:'订单状态',width:50,formatter: function(value,row,index){
						if (value=='1'){
							return '<font style="color:green;">已处理</font>';
						} else {
							return '<font style="color:red;">未处理</font>';
						}
					}},
					{field:'opt',title:'操作',width:70,formatter: function(value,row,index){
						return row.state=='1'?'<font style="color:green;">已开通</font>':'<a href="javascript:Home.servReg(\''+row.id+'\',\''+row.prdCode+'\',\''+'\',\''+row.ecName+'\',\''+row.ecCode+'\',\''+row.priority+'\',\''+row.adminUser + '@' + row.ecCode + '\',\''+row.adminUfid+'\')">开通</a>';
					}}
				]]
			});
		},
		//初始化服务开通订单列表
		initServReggrid : function(){
			$('#servReggrid').datagrid({
				url:'/interface/servOrderList.htm?optType=0',
				fit:true,
				idField:'id',
				striped:true,
				nowrap:true,
				loadMsg:'加载中 ……',
				animate:true,
				checkbox:true,
				pagination:true,
				rownumbers:true,
				fitColumns:true,
				border:true,
				columns:[[
					{field:'id',title:'',width:50,checkbox : true},
					{field:'area',title:'地市',width:40},
					{field:'ec_name',title:'企业名称',width:200},
				    {field:'ec_code',title:'企业编码',width:100},
				    {field:'prd_code',title:'产品类型',width:70,formatter:function(value,rowData,index){
				    	if(value == 'J0185'){
				    		return '销售管家';
				    	}else if(value == 'J0186'){
				    		return '外勤管家';
				    	}else{
				    		return '未知产品';
				    	}
				    }},
				    {field:'priority',title:'管理员手机',width:80},
				    {field:'admin_user',title:'管理员用户名',width:80,formatter: function(value,row,index){
				    	return value + '@' + row.ec_code;
					}},
					 {field:'login_url',title:'登录地址',width:200,formatter: function(value,row,index){
					    	if(value && value!=''){
						    	var url = basePath + 'login/' + value;
								return url;
					    	}else{
					    		return '';
					    	}
						}},
				    /*{field:'access_no',title:'登录地址',width:200,formatter: function(value,row,index){
				    	if(value && value!=''){
					    	var url = basePath + 'login/' + value;
							return url;
				    	}else{
				    		return '';
				    	}
					}},*/
				    {field:'admin_ufid',title:'管理员密码',width:60},
				    {field:'inter_update_time',title:'订单时间',width:80},
				    {field:'state',title:'订单状态',width:50,formatter: function(value,row,index){
						if (value=='1'){
							return '<font style="color:green;">已处理</font>';
						} else {
							return '<font style="color:red;">未处理</font>';
						}
					}},
					{field:'opt',title:'操作',width:50,formatter: function(value,row,index){
						var str = row.state=='1'?'<font style="color:green;">已开通</font>':'<a href="javascript:Home.servReg(\''+row.id+'\',\''+row.prd_code+'\',\''+row.ec_name+'\',\''+row.ec_code+'\',\''+row.priority+'\',\''+row.admin_user + '@' + row.ec_code + '\',\''+row.admin_ufid+'\')">开通</a>';
						return str;
					}},
					{field:'opt_',title:'查看',width:40,formatter: function(value,row,index){
						var str = '<a href="javascript:Home.detal(\''+row.ec_code+'\')" >查看</a>';
						return str;
					}}
				]]
			});
		},
		
		//查看成员信息
		detal:function(id){
			Ict.openWin2("人员信息",650,350,"/interface/homeEmployees.htm?id="+id);
		}	
	};
}();

$(function(){
	$.pp = $('#portal');
	$.qydd = $('#qydd');
	$.grid = $('#grid');
	$.qyddTab = $('#qyddTab');
	$.servReggrid = $('#servReggrid');
	//
	Home.init();
});
